#pragma once
#include <vector>
#include "Geometry.h"
#include "quadTree.h"

class Node
{
public:
	Node(const Vector2& position, int index) : position_(position), index_(index) {}
	Vector2 position_;
	int index_;
};

class NodeDistanceCompare
{
public:
	NodeDistanceCompare(const Vector2& v) : v_(v) {}
	bool operator()(const Node& node1, const Node& node2) const
	{
		return (node1.position_ - v_).magnitude() < (node2.position_ - v_).magnitude();
	}

protected:
	Vector2 v_;
};

class NearestNeighbors
{
public:
	NearestNeighbors(void);
	virtual ~NearestNeighbors(void);

	void init(float minX, float maxX, float minY, float maxY);

	void addVertex(const Vector2& v, int index);
	void kNearestNeighbors(const Vector2& v, std::vector<int>& neighborIndices, unsigned int k);

protected:
	std::vector<Node> nodes_;
	QuadTree* tree_;
	Vector2 spaceMin_;
	Vector2 spaceMax_;
	Vector2 spaceSize_;
};

